package com.maxdu.labs.stt.fakes;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.example.stt.R;
import com.facebook.Session;
import com.facebook.SessionState;
import com.maxdu.labs.stt.activities.InviteFriendsActivity;
import com.maxdu.labs.stt.activities.MainTestMenuActivity;
import com.maxdu.labs.stt.activities.MyFriendsActivity;
import com.maxdu.labs.stt.activities.PendingFriendRequestActivity;
import com.maxdu.labs.stt.activities.PendingTPlanRequestsActivity;
import com.maxdu.labs.stt.activities.SeeMyTPlansActivity;
import com.maxdu.labs.stt.activities.SeeTPlanWeeklyActivity;
import com.maxdu.labs.stt.activities.TestDrawerActivity;
import com.maxdu.labs.stt.constants.Constants;

public class FakeMenuActivity extends ActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_fake_menu);
		
		//Initialize FB
		Session.openActiveSession(this, true, new Session.StatusCallback() {
		    @Override
		    public void call(Session session, SessionState state, Exception exception) {
		        if(session.isOpened()) {
		            Log.w(Constants.LOG_TAG, "FB session opened successfully");
		        } else {
		        	if(exception != null){
		        		Log.w(Constants.LOG_TAG, "FB session not opened ... " + exception.toString());
		        	}
		        }
		    }
		});
		
		
		Button buttonInviteFriends = (Button) findViewById(R.id.invite_friends_btn);
		
		buttonInviteFriends.setOnClickListener(new OnClickListener() {           
  		  @Override
  		  public void onClick(View v) 
  		  {
  			Intent intent = new Intent(v.getContext(), InviteFriendsActivity.class);
  			startActivity(intent);
  		  }    
  		});
		
		Button buttonPendingFriendRequest = (Button) findViewById(R.id.pending_friend_request_btn);
		buttonPendingFriendRequest.setOnClickListener(new OnClickListener() {           
	  		  @Override
	  		  public void onClick(View v) 
	  		  {
	  			Intent intent = new Intent(v.getContext(), PendingFriendRequestActivity.class);
	  			startActivity(intent);
	  		  }    
	  	});
			
		
		Button myFriendsBtn = (Button) findViewById(R.id.my_friends_btn);
		myFriendsBtn.setOnClickListener(new OnClickListener() {           
	  		  @Override
	  		  public void onClick(View v) 
	  		  {
	  			Intent intent = new Intent(v.getContext(), MyFriendsActivity.class);
	  			startActivity(intent);
	  		  }    
	  	});
		
		Button createTrainingBtn = (Button) findViewById(R.id.create_training_btn);
		createTrainingBtn.setText("Test  DRAWER");
		createTrainingBtn.setOnClickListener(new OnClickListener() {           
	  		  @Override
	  		  public void onClick(View v) 
	  		  {
	  			Intent intent = new Intent(v.getContext(), TestDrawerActivity.class);
	  			startActivity(intent);
	  		  }    
	  	});
		
		
		
		Button buttonSeeTrainingRequests = (Button) findViewById(R.id.btn_see_training_requests);
		
		buttonSeeTrainingRequests.setOnClickListener(new OnClickListener() {           
  		  @Override
  		  public void onClick(View v) 
  		  {
  			Intent intent = new Intent(v.getContext(), PendingTPlanRequestsActivity.class);
  			startActivity(intent);
  		  }    
  		});
		
		
		
		Button buttonSeeTPlanWeekly = (Button) findViewById(R.id.btn_see_tplan_weekly);
		
		buttonSeeTPlanWeekly.setOnClickListener(new OnClickListener() {           
  		  @Override
  		  public void onClick(View v) 
  		  {
  			  
    			Intent intent = new Intent(v.getContext(), MainTestMenuActivity.class);
    			startActivity(intent);
  		  }    
  		});
		
		Button buttonSeeMyTPlans = (Button) findViewById(R.id.btn_see_my_tplans);
		
		buttonSeeMyTPlans.setOnClickListener(new OnClickListener() {           
  		  @Override
  		  public void onClick(View v) 
  		  {
  			  
    			Intent intent = new Intent(v.getContext(), SeeMyTPlansActivity.class);
    			startActivity(intent);
  		  }    
  		});
	}

	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_main_actions, menu);
 
        return super.onCreateOptionsMenu(menu);
    }
	
	/**
     * On selecting action bar icons
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Take appropriate action for each action item click
        switch (item.getItemId()) {
        case R.id.action_search:
            // search action
            return true;
        case R.id.action_location_found:
            // location found
            LocationFound();
            return true;
        case R.id.action_refresh:
            // refresh
            return true;
        case R.id.action_help:
            // help action
            return true;
        case R.id.action_check_updates:
            // check for updates action
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
 
    /**
     * Launching new activity
     * */
    private void LocationFound() {
        Intent i = new Intent(FakeMenuActivity.this, SeeTPlanWeeklyActivity.class);
        startActivity(i);
    }
}
